<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>左右切换</title>
<link href="<%=request.getContextPath()%>/views/sysdefault/js2draft/css/orso.css" rel="stylesheet"/>
<link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/toastr/toastr.min.css" rel="stylesheet">
</head>
<body>
<div class="top" align="center">
选择表：
<select id="tableName" name="tableName">
    <c:forEach items="${listTbName}" var="item" varStatus="i">
       <option value="${item}" >${item}</option>
	</c:forEach>
</select>
</div>
<div class="box">
	<div class="box_l">
	   <c:forEach items="${listTbFlow}" var="item" varStatus="i">
	       <li>${item}</li>
	   </c:forEach>
	</div>
	<div class="box_m">
		<a href="javascript:" id="top">上移</a>
		<a href="javascript:" id="left">向左</a>
		<a href="javascript:" id="right">向右</a>
		<a href="javascript:" id="bottom">下移</a>
	</div>
	<div class="box_r">
	   <c:forEach items="${oldlistTbFlow}" var="item" varStatus="i">
	       <li>${item}</li>
	   </c:forEach>
	</div>
</div>
<br/>
<div class="down">
<input type="button"  onclick="saveFlow();" value="保存"/>
</div>
<script src="<%=request.getContextPath()%>/views/sysdefault/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/views/sysdefault/js2draft/js/jquery-1.7.2.min.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/views/sysdefault/js2draft/js/orso.js" ></script>
<script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/layer/layer.js"></script>
<script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/toastr/toastr.min.js"></script>
<script>
	$(document).ready(function(){
		$(".box").orso({
			boxl:".box_l",//左边大盒子
			boxr:".box_r",//右边大盒子
			boxlrX:"li",//移动小盒子
			boxon:"on",//点击添加属性
			idclass:true,//添加的属性是否为class//true=class; false=id;
			boxlan:"#left",//单个向左移动按钮
			boxran:"#right",//单个向右移动按钮
			boxtan:"#top",//单个向上移动按钮
			boxban:"#bottom",//单个向下移动按钮
			boxalllan:"#allleft",//批量向左移动按钮
			boxallran:"#allright",//批量向右移动按钮
			boxalltan:"#alltop",//移动第一个按钮
			boxallban:"#allbottom"//移动最后一个按钮
		})
	});
</script>
<script type="text/javascript">
var basePath = '<%=request.getContextPath()%>';
var tablename ="";
function saveFlow(){
	var MODELTB_FlowOneTbName = "调查统计月报表（表一）";
	var MODELTB_FlowTwoTbName = "存在问题和情况变更统计表二";
	var MODELTB_FlowThereChangeTbName = "调查统计季报表三（变更表）";
	var MODELTB_FlowThereChickTbName = "调查统计季报表三（核查表）";
	var MODELTB_FlowFourTbName = "调查统计季报表四（整改表）";
	var Final_CheckPer = "审核材料收集者";
	tablename=$("#tableName").val();
	var temp = 0;
	var flowlsit = $(".box_r li");
	var flowstr="";
	if(flowlsit.length==0){
		alert("请编辑"+tablename+"的审批流程");
		return false;
	}else{
		//判断用户选择的是哪张表  根据名称得到用户所选择表的值 确定该表需要的流程个数
		if(tablename == MODELTB_FlowOneTbName){
			temp=3;
		}else if(tablename == MODELTB_FlowTwoTbName){
			temp=3;
		}else if(tablename == MODELTB_FlowThereChangeTbName){
			temp=2;
		}else if(tablename == MODELTB_FlowThereChickTbName){
			temp=8;
		}else if(tablename == MODELTB_FlowFourTbName){
			temp=10;
		}
		if(temp > flowlsit.length){
			alert("警告！缺少审批流程");
			return false;
		}
		if(temp < flowlsit.length){
			alert("警告！审批流程过多");
			return false;
		}
		if(flowlsit[flowlsit.length-1].innerHTML!= Final_CheckPer){
			alert("警告！审批流程最后一步必须为 : "+Final_CheckPer);
			return false;
		}
		flowstr+=flowlsit[0].innerHTML
		for(var m =1;m<flowlsit.length;m++){
			flowstr+="###"+flowlsit[m].innerHTML;
		}
	}
	layer.confirm('确定要为' + $("#tableName").val() + '保存改审批流程么？', {
		  btn: ['确定','取消'] //按钮
		}, function(index){
			layer.close(index);
			$.ajax({
				type : "POST",
				url : basePath + "/bgGlutTablePoliceFlow/addFlow.ido",
				data : {"tablename" : tablename, "flowstr" : flowstr},
				dataType : "json",
				success : function(msg) { 
					if (msg.errCode == '1') {
						layerCallBack('1');
						parent.location.reload();
						parent.closeSunWindow();
					}else{
						toastr.error(msg.errMsg, "提示");
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					toastr.error("系统出错！", "提示");
				},
				beforeSend : function(XMLHttpRequest){
					layer.load(0, {
						  shade: [0.3,'#ccc'] //0.1透明度的白色背景
						});
				},
				complete : function(XMLHttpRequest, textStatus){
					layer.closeAll();
				}
			});
			
		}, function(){
			
		}); 
	//操作成功
    var layerCallBack = function(status){
    	if(status == '1'){
    		layer.closeAll();
    		toastr.success("操作成功！", "提示");
    		setTimeout(function(){
    			location.reload();
    		}, 1000);
    	}else if(status == '2'){
    		layer.closeAll();
    		toastr.success("操作成功！", "提示");
    	}
    }
	
}
</script>
</body>
</html>